﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity.InterceptionExtension;
using System.Reflection;
using Microsoft.Practices.ObjectBuilder2;

namespace Artech.PetShop.Common
{
    public class BaseTypeMatchingRule : IMatchingRule
    {
        private readonly List<Type> matches;

        public BaseTypeMatchingRule(IEnumerable<Type> matches)
        {
            Guard.ArgumentNotNull(matches, "matches");
            this.matches = new List<Type>(matches);
        }

        public bool Matches(MethodBase member)
        {
            Guard.ArgumentNotNull(member, "member");
            foreach (Type baseType in this.matches)
            {
                if (baseType.IsAssignableFrom(member.DeclaringType))
                {
                    return true;
                }
            }
            return false;
        }       
    }
}